package com.jiantong.admin.controller.dongjiantong;

import com.jiantong.admin.dto.CityAreaDto;
import com.jiantong.admin.model.PagingMz;
import com.jiantong.user.model.*;
import com.jiantong.user.service.*;


import com.jiantong.work.model.yangzhibaoxian.*;

import com.jiantong.work.service.yangzhibaoxian.*;

import io.terminus.boot.rpc.common.annotation.RpcConsumer;
import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import io.terminus.pampas.openplatform.exceptions.OPClientException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.sampled.Line;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by ThinkPad on 2017/9/12.
 */
@Slf4j
@Controller
@RequestMapping("/djt/insurance/")
public class insuranceController {
    @RpcConsumer
    private BreedFactoryReadService breedFactoryReadService;
    @RpcConsumer
    private UserProfileReadService userProfileReadService;
    @RpcConsumer
    private UserReadService userReadService;
    @RpcConsumer
    private OrganizationReadService organizationReadService;
    @RpcConsumer
    private OrganizationUserReadService organizationUserReadService;

    @RpcConsumer
    private GovernmentUserDutyReadService governmentUserDutyReadService;
    @RpcConsumer
    private InsuranceApplicationService insuranceApplicationService;
    @RpcConsumer
    private ClaimsSettlementService claimsSettlementService;
    @RpcConsumer
    private InsuranceTemplateService insuranceTemplateService;
    @RpcConsumer
    private InsuranceRetailService insuranceRetailService;
    @RpcConsumer
    private InsuranceAreaService insuranceAreaService;
    @RpcConsumer
    private ClaimsResultService claimsResultService;
    @RpcConsumer
    private InformService informService;

    @RequestMapping("tab")
    public String tab(Model model, @RequestParam Long id) {
        InsuranceApplication insuranceApplication = insuranceApplicationService.findById(id).getResult();
        User user = (User) userReadService.findById(insuranceApplication.getReceiver_id()).getResult();
        insuranceApplication.setReceiver_phone(user.getMobile());
        model.addAttribute("insuranceApplication", insuranceApplication);
        return "djt/insurance/Tab";
    }

    /**
     * 理赔申请单详情
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("tab1")
    public String tab1(Model model, @RequestParam Long id) {

        ClaimsSettlement claimsSettlement = claimsSettlementService.findById(id).getResult();
        Map map = new HashMap();
        map.put("insured_breed_id", claimsSettlement.getBreed_factory_id());
        List<ClaimsResult> claimsResultList = claimsResultService.list(map).getResult();
        if (claimsResultList != null)
            claimsSettlement.setClaims_count(claimsResultList.size());

        User user = (User) userReadService.findById(claimsSettlement.getReceiver_id()).getResult();
        claimsSettlement.setPhone(user.getMobile());
        model.addAttribute("claimsSettlement", claimsSettlement);
        return "djt/insurance/Tab1";
    }

    /**
     * 进入最新投保申请单
     *
     * @param response
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("index")
    public String insuranceNew(HttpServletResponse response, HttpServletRequest request, Model model) {
        Map map = getarea(response, request);
        model.addAttribute("username", map.get("username"));
        model.addAttribute("cityAreaDtoList", map.get("cityAreaDtoList"));
        model.addAttribute("breedFactoryList", map.get("breedFactorys"));

        return "djt/insurance/insuranceReportNew";
    }

    /**
     * 理赔申请单
     *
     * @param page
     * @param rows
     * @param breedFactoryId
     * @param time1
     * @param time2
     * @return
     */
    @RequestMapping("claimReportNew/ajax")
    @ResponseBody
    public PagingMz<ClaimsSettlement> claimsSettlementList(@RequestParam(required = false) Integer page,
                                                           @RequestParam(required = false) Integer rows,
                                                           @RequestParam(required = false) String breedFactoryId,
                                                           @RequestParam(required = false) Date time1,
                                                           @RequestParam(required = false) Date time2) {
        if (page == null) {
            page = 1;
        }
        if (rows == null) {
            rows = 20;
        }


        PageInfo pageInfo = new PageInfo(page, rows);
        Map map = new HashMap();
        if (breedFactoryId == null) {
            map.put("breedIDList", null);
        } else {
            List<Long> list1 = new ArrayList<>();
            String[] list = breedFactoryId.split(",");

            for (int i = 0; i < list.length; i++) {
                int id = Integer.parseInt(list[i]);
                Long id1 = Integer.toUnsignedLong(id);
                list1.add(id1);
            }
            map.put("breedIDList", list1);
        }
        map.put("check_status", 0);
        map.put("time1", time1);
        map.put("time2", time2);
        Paging<ClaimsSettlement> claimsSettlementPaging = claimsSettlementService.ping(pageInfo.getOffset(), pageInfo.getLimit(), map).getResult();
        Long records = claimsSettlementPaging.getTotal(); //总记录数
        Long pagetotal = (records - 1) / rows + 1; //得到总页数
        return new PagingMz<ClaimsSettlement>(pagetotal, records, page, claimsSettlementPaging.getData());
    }

    @RequestMapping("insuranceReportNew/ajax")
    @ResponseBody
    public PagingMz<InsuranceApplication> insuranceApplicationList(@RequestParam(required = false) Integer page,
                                                                   @RequestParam(required = false) Integer rows,
                                                                   @RequestParam(required = false) String breedFactoryId,
                                                                   @RequestParam(required = false) Date time1,
                                                                   @RequestParam(required = false) Date time2) {
        if (page == null) {
            page = 1;
        }
        if (rows == null) {
            rows = 20;
        }


        PageInfo pageInfo = new PageInfo(page, rows);
        Map map = new HashMap();
        if (breedFactoryId == null) {
            map.put("breedIDList", null);
        } else {
            List<Long> list1 = new ArrayList<>();
            String[] list = breedFactoryId.split(",");

            for (int i = 0; i < list.length; i++) {
                int id = Integer.parseInt(list[i]);
                Long id1 = Integer.toUnsignedLong(id);
                list1.add(id1);
            }
            map.put("breedIDList", list1);
        }
        map.put("check_status", 0);
        map.put("time1", time1);
        map.put("time2", time2);
        Paging<InsuranceApplication> insuranceApplicationPaging = insuranceApplicationService.ping(pageInfo.getOffset(), pageInfo.getLimit(), map).getResult();
        Long records = insuranceApplicationPaging.getTotal(); //总记录数
        Long pagetotal = (records - 1) / rows + 1; //得到总页数
        return new PagingMz<InsuranceApplication>(pagetotal, records, page, insuranceApplicationPaging.getData());
    }

    /**
     * 进入历史投保申请单
     *
     * @param response
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("insuranceReport")
    public String insuranceReport(HttpServletResponse response, HttpServletRequest request, Model model) {
        Map map = getarea(response, request);
        model.addAttribute("username", map.get("username"));
        model.addAttribute("cityAreaDtoList", map.get("cityAreaDtoList"));
        model.addAttribute("breedFactoryList", map.get("breedFactorys"));
        return "djt/insurance/insuranceReport";
    }


    @RequestMapping("insuranceReportOld/ajax")
    @ResponseBody
    public PagingMz<InsuranceApplication> insuranceApplicationListOld(@RequestParam(required = false) Integer page,
                                                                      @RequestParam(required = false) Integer rows,
                                                                      @RequestParam(required = false) String breedFactoryId,
                                                                      @RequestParam(required = false) Date time1,
                                                                      @RequestParam(required = false) Date time2) {
        if (page == null) {
            page = 1;
        }
        if (rows == null) {
            rows = 20;
        }


        PageInfo pageInfo = new PageInfo(page, rows);
        Map map = new HashMap();
        if (breedFactoryId == null) {
            map.put("breedIDList", null);
        } else {
            List<Long> list1 = new ArrayList<>();
            String[] list = breedFactoryId.split(",");

            for (int i = 0; i < list.length; i++) {
                int id = Integer.parseInt(list[i]);
                Long id1 = Integer.toUnsignedLong(id);
                list1.add(id1);
            }
            map.put("breedIDList", list1);
        }
        List<Integer> listStatus = Arrays.asList(1, 2, 3, 4, 5);
        map.put("Liststatus", listStatus);
        map.put("time1", time1);
        map.put("time2", time2);
        Paging<InsuranceApplication> insuranceApplicationPaging = insuranceApplicationService.ping(pageInfo.getOffset(), pageInfo.getLimit(), map).getResult();
        Long records = insuranceApplicationPaging.getTotal(); //总记录数
        Long pagetotal = (records - 1) / rows + 1; //得到总页数
        return new PagingMz<InsuranceApplication>(pagetotal, records, page, insuranceApplicationPaging.getData());
    }


    /**
     * 历史理赔单列表
     *
     * @param page
     * @param rows
     * @param breedFactoryId
     * @param checkStatus
     * @param time1
     * @param time2
     * @return
     */
    @RequestMapping("claimReportOld/ajax")
    @ResponseBody
    public PagingMz<ClaimsSettlement> claimsSettlementListOld(@RequestParam(required = false) Integer page,
                                                              @RequestParam(required = false) Integer rows,
                                                              @RequestParam(required = false) String breedFactoryId,
                                                              @RequestParam(required = false) String checkStatus,
                                                              @RequestParam(required = false) Date time1,
                                                              @RequestParam(required = false) Date time2) {
        if (page == null)
            page = 1;
        if (rows == null)
            rows = 20;


        PageInfo pageInfo = new PageInfo(page, rows);
        Map map = new HashMap();

        if (breedFactoryId == null)
            map.put("breedIDList", null);
        else {
            List<Long> list = new ArrayList<>();
            String[] list1 = breedFactoryId.split(",");

            for (int i = 0; i < list1.length; i++) {
                int id = Integer.parseInt(list1[i]);
                Long id1 = Integer.toUnsignedLong(id);
                list.add(id1);
            }
            map.put("breedIDList", list);
        }

        if (checkStatus == null)
            map.put("checkStatusList", null);
        else {
            List<Long> list = new ArrayList<>();
            String[] list1 = checkStatus.split(",");

            for (int i = 0; i < list1.length; i++) {
                int id = Integer.parseInt(list1[i]);
                Long id1 = Integer.toUnsignedLong(id);
                list.add(id1);
            }
            map.put("checkStatusList", list);
        }
        map.put("time1", time1);
        map.put("time2", time2);
        Paging<ClaimsSettlement> ClaimsSettlementPaging = claimsSettlementService.ping(pageInfo.getOffset(), pageInfo.getLimit(), map).getResult();
        Long records = ClaimsSettlementPaging.getTotal(); //总记录数
        Long pagetotal = (records - 1) / rows + 1; //得到总页数
        return new PagingMz<ClaimsSettlement>(pagetotal, records, page, ClaimsSettlementPaging.getData());
    }

    /**
     * 已提交理赔申请单
     *
     * @param response
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("claimReportNew")
    public String claimReportNew(HttpServletResponse response, HttpServletRequest request, Model model) {
        Map map = getarea(response, request);
        model.addAttribute("username", map.get("username"));
        model.addAttribute("cityAreaDtoList", map.get("cityAreaDtoList"));
        model.addAttribute("breedFactoryList", map.get("breedFactorys"));
        return "djt/insurance/claimReportNew";
    }

    /**
     * 历史理赔申请单
     *
     * @param response
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("claimReport")
    public String claimReport(HttpServletResponse response, HttpServletRequest request, Model model) {
        Map map = getarea(response, request);
        model.addAttribute("username", map.get("username"));
        model.addAttribute("cityAreaDtoList", map.get("cityAreaDtoList"));
        model.addAttribute("breedFactoryList", map.get("breedFactorys"));
        return "djt/insurance/claimReport";
    }

    @RequestMapping("claimAdd/ajax")
    public String claimAdd(HttpServletResponse response, HttpServletRequest request, Model model) {
        Map map = getarea(response, request);
        model.addAttribute("username", map.get("username"));
        model.addAttribute("cityAreaDtoList", map.get("cityAreaDtoList"));
        model.addAttribute("breedFactoryList", map.get("breedFactorys"));
        List<InsuranceTemplate> insuranceTemplateList = insuranceTemplateService.list(new HashMap()).getResult();
        model.addAttribute("insuranceTemplateList", insuranceTemplateList);
        return "djt/insurance/addClaim";
    }

    /**
     * 获取保单号码
     *
     * @param breedFactoryID
     * @param item
     * @return
     */
    @RequestMapping("claimInsuredNumber/ajax")
    @ResponseBody
    public InsuranceApplication claimInsuredNumber(@RequestParam("breedFactoryID") String breedFactoryID,
                                                   @RequestParam("item") String item) {
        InsuranceApplication insuranceApplication = null;
        Map map = new HashMap();
        if (breedFactoryID == null)
            map.put("breed_factory_id", null);
        else {
            if (Integer.parseInt(breedFactoryID) == 0) {
                map.put("breed_factory_id", null);
            } else {
                map.put("breed_factory_id", breedFactoryID);
            }
        }
        List<InsuranceRetail> insuranceRetailList = insuranceRetailService.list(map).getResult();

        List<Long> idList = new ArrayList<>();
        for (InsuranceRetail insuranceRetail : insuranceRetailList) {
            idList.add(insuranceRetail.getApplication_id());
        }

        Map map1 = new HashMap();
        //SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        map1.put("date", new Date());
        map1.put("idList", idList);
        map1.put("item", item);
        List<InsuranceApplication> insuranceApplicationList = insuranceApplicationService.list(map1).getResult();
        if (insuranceApplicationList != null) {
            if (insuranceApplicationList.size() == 1) {
                insuranceApplication = insuranceApplicationList.get(0);
            }
        }
        return insuranceApplication;
    }

    @RequestMapping("claimAdd1/ajax")
    @ResponseBody
    public Long createClaimsSettlement(
            @RequestParam String item,
            @RequestParam String amount,
            @RequestParam String case_date,
            @RequestParam String insured_number,
            @RequestParam String breed_factory_name,
            @RequestParam Long breed_factory_id,
            @RequestParam String phone,
            @RequestParam String address,
            @RequestParam Long insurance_application_id) throws ParseException {

        ClaimsSettlement claimsSettlement = new ClaimsSettlement();
        claimsSettlement.setInsurance_application_id(insurance_application_id);
        claimsSettlement.setItem(item);
        claimsSettlement.setAmount(Integer.parseInt(amount));
        claimsSettlement.setInsured_number(insured_number);
        claimsSettlement.setBreed_factory_id(breed_factory_id);
        claimsSettlement.setBreed_factory_name(breed_factory_name);
        claimsSettlement.setPhone(phone);
        claimsSettlement.setAddress(address);
        SimpleDateFormat sdformate = new SimpleDateFormat("yyyy-MM-dd");
        Date d = sdformate.parse(case_date);
        claimsSettlement.setCase_date(d);


        BreedFactory breedFactory = breedFactoryReadService.findById(claimsSettlement.getBreed_factory_id()).getResult();
        claimsSettlement.setUserId(breedFactory.getUserId());
        //市
        String cityID = breedFactory.getCityId().toString();
        if (cityID.length() == 1) {
            cityID = "0" + cityID;
        }
        //县
        String regionID = breedFactory.getRegionId().toString();
        if (regionID.length() == 1) {
            regionID = "0" + regionID;
        }
        // 镇
        String streetId = null;
        if (breedFactory.getStreetId() == null) {
            streetId = "000";
        } else {
            streetId = breedFactory.getStreetId().toString();
        }

        if (streetId.length() == 1) {
            streetId = "00" + streetId;
        }
        if (streetId.length() == 2) {
            streetId = "0" + streetId;
        }
        //村

        String villageId = null;
        if (breedFactory.getVillageId() == null) {
            villageId = "000";
        } else {
            villageId = breedFactory.getVillageId().toString();
        }

        if (villageId.length() == 1) {
            villageId = "00" + villageId;
        }
        if (villageId.length() == 2) {
            villageId = "0" + villageId;
        }
        String area = breedFactory.getProvinceId().toString()
                + cityID
                + regionID
                + streetId
                + villageId;

        InsuranceArea insuranceArea = insuranceAreaService.findByAreaCode(area);
        Long receiver_id = -1L;
        String receiver_name = null;
        if (insuranceArea != null) {
            receiver_id = insuranceArea.getUser_id();
            receiver_name = insuranceArea.getUser_name();
        }

        claimsSettlement.setReceiver_id(receiver_id);
        claimsSettlement.setReceiver_name(receiver_name);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmm");
        String number = sdf.format(new Date());
        claimsSettlement.setNumber("CLA" + number);
        claimsSettlement.setCheck_status(0);
        Map map = new HashMap();
        map.put("insured_breed_id", claimsSettlement.getBreed_factory_id());
        List<ClaimsResult> claimsResultList = claimsResultService.list(map).getResult();
        Double money = 0.00;
        if (claimsResultList.size() != 0) {
            for (ClaimsResult claimsResult : claimsResultList) {
                money += claimsResult.getPay_money();
            }
        }

        claimsSettlement.setClaims_money(money);
        claimsSettlement.setClaims_count(claimsResultList.size());
        return claimsSettlementService.create(claimsSettlement);
    }

    @RequestMapping("inform")
    public String informHtml(HttpServletRequest request,HttpServletResponse response,Model model){
        Map map = getarea(response, request);
        model.addAttribute("username", map.get("username"));
        model.addAttribute("userId",map.get("userId"));
        return "djt/insurance/informNew";
    }

    /**
     * inform页面获取通知用户列表
     * @param response
     * @param request
     * @return
     */
    @RequestMapping("getUserList/ajax")
    @ResponseBody
    public List<OrganizationUser> getUserList(HttpServletRequest request,HttpServletResponse response,Long userId){
        OrganizationUser organizationUser = null;
        Map map = new HashMap();
        if (userId != null)
            //组织人员信息表中根据用户id查询到对应的数据
            organizationUser = organizationUserReadService.findOrganizationUserByUserId(userId).getResult();
        if (organizationUser != null)
            map.put("organizationId",organizationUser.getOrganizationId());
        //根据查询到的组织id查找到该组织下所有人员列表
        return organizationUserReadService.selectList(map).getResult();
    }

    @RequestMapping("addInform/ajax")
    @ResponseBody
    public Integer addInform(@RequestParam Integer type,
                          @RequestParam String message,
                          @RequestParam String set_message_name,
                          @RequestParam long set_message_id,
                          @RequestParam String userIdList){

        //遍历要接收通知人的列表
        Integer con = null;
        if (message != null && message != ""){
            List<Inform> list = new ArrayList<>();
            String[] list1 = userIdList.split(",");
            for (int i = 0; i < list1.length; i++) {
                Inform inform = new Inform();
                int getMessageId = Integer.parseInt(list1[i]);
                Long get_message_id = Integer.toUnsignedLong(getMessageId);
                inform.setGet_message_id(get_message_id);
                inform.setType(type);
                inform.setMessage(message);
                inform.setSet_message_id(set_message_id);
                inform.setSet_message_name(set_message_name);
                inform.setStatus(1);
                list.add(inform);
            }
            con = informService.creates(list);
        }
        return con;
    }

    public Map getarea(HttpServletResponse response, HttpServletRequest request) {
        List<String> list = new ArrayList<>();
        list.add("province");
        list.add("city");
        list.add("region");
        list.add("street");
        list.add("village");
        Cookie[] cookies = null;
        cookies = request.getCookies();
        String name = "";
        Map map = new HashMap();
        for (Cookie cookie : cookies) {

            if (cookie.getName().equals("djtid")) {
                String id = cookie.getValue();
                int Id = Integer.parseInt(id);
                Response<User> userResponse = userReadService.findById(Integer.toUnsignedLong(Id));
                name = userResponse.getResult().getName();
                map.put("userId", userResponse.getResult().getId());
                map.put("username", name);
                OrganizationUser organizationUser = organizationUserReadService.findOrganizationUserByUserId(userResponse.getResult().getId()).getResult();
                switch (userResponse.getResult().getAreaLevel()) {
                    case 1:

                        UserProfile userProfile = userProfileReadService.findUserProfileById(userResponse.getResult().getId()).getResult();
                        String Province = userProfile.getProvince();


                        //获取所有省下城市

                        Map map1 = new HashMap();
                        map1.put("area1", list.get(1));
                        map1.put("area2", list.get(0));
                        map1.put("area3", Province);
                        List<String> citys = breedFactoryReadService.serachAllregion1(map1);
                        //获取城市下所有区
                        List<CityAreaDto> cityAreaDtoList = new ArrayList<>();
                        for (String city : citys) {
                            CityAreaDto cityAreaDto = new CityAreaDto();
                            Map map2 = new HashMap();
                            map2.put("area1", list.get(2));
                            map2.put("area2", list.get(1));
                            map2.put("area3", city);
                            List<String> regions = breedFactoryReadService.serachAllregion1(map2);
                            cityAreaDto.setCity(city);
                            cityAreaDto.setRegions(regions);
                            cityAreaDtoList.add(cityAreaDto);

                        }
                        if (organizationUser.getOrganizationType() == 3) {
                            Map map6 = new HashMap();
                            map6.put("province", Province);
                            List<BreedFactory> breedFactoryList = (List<BreedFactory>) breedFactoryReadService.findByArea(map6).getResult();
                            map.put("breedFactorys", breedFactoryList);
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        } else {
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        }

                        map.put("cityAreaDtoList", cityAreaDtoList);


                        //switch break;
                        break;
                    case 2:
                        UserProfile userProfile2 = userProfileReadService.findUserProfileById(userResponse.getResult().getId()).getResult();
                        String city1 = userProfile2.getCity();

                        //获取所有省下城市

                        Map map21 = new HashMap();
                        map21.put("area1", list.get(2));
                        map21.put("area2", list.get(1));
                        map21.put("area3", city1);
                        List<String> citys2 = breedFactoryReadService.serachAllregion1(map21);
                        //获取城市下所有区
                        List<CityAreaDto> cityAreaDtoList1 = new ArrayList<>();
                        for (String city : citys2) {
                            CityAreaDto cityAreaDto = new CityAreaDto();
                            Map map2 = new HashMap();
                            map2.put("area1", list.get(3));
                            map2.put("area2", list.get(2));
                            map2.put("area3", city);
                            List<String> regions = breedFactoryReadService.serachAllregion1(map2);
                            cityAreaDto.setCity(city);
                            cityAreaDto.setRegions(regions);
                            cityAreaDtoList1.add(cityAreaDto);

                        }
                        if (organizationUser.getOrganizationType() == 3) {
                            Map map7 = new HashMap();
                            map7.put("city", city1);
                            List<BreedFactory> breedFactoryList1 = (List<BreedFactory>) breedFactoryReadService.findByArea(map7).getResult();
                            map.put("breedFactorys", breedFactoryList1);

                        } else {
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        }
                        map.put("cityAreaDtoList", cityAreaDtoList1);

                        //switch break;
                        break;
                    case 3://区
                        UserProfile userProfile3 = userProfileReadService.findUserProfileById(userResponse.getResult().getId()).getResult();
                        String region = userProfile3.getRegion();

                        List<CityAreaDto> cityAreaDtoList3 = new ArrayList<>();
                        CityAreaDto cityAreaDto = new CityAreaDto();
                        List<String> regions = new ArrayList<>();
                        regions.add(region);
                        cityAreaDto.setCity(userProfile3.getCity());
                        cityAreaDto.setRegions(regions);
                        cityAreaDtoList3.add(cityAreaDto);


                        if (organizationUser.getOrganizationType() == 3) {
                            Map map36 = new HashMap();
                            map36.put("region", region);
                            List<BreedFactory> breedFactoryList3 = (List<BreedFactory>) breedFactoryReadService.findByArea(map36).getResult();
                            map.put("breedFactorys", breedFactoryList3);
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        } else {
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        }
                        map.put("cityAreaDtoList", cityAreaDtoList3);


                        //switch break;
                        break;
                    case 4://镇
                        UserProfile userProfile4 = userProfileReadService.findUserProfileById(userResponse.getResult().getId()).getResult();
                        String street = userProfile4.getStreet();

                        //获取所有镇下所有村

                        Map map41 = new HashMap();
                        map41.put("area1", list.get(4));
                        map41.put("area2", list.get(3));
                        map41.put("area3", street);

                        List<String> citys4 = breedFactoryReadService.serachAllregion1(map41);//所有村

                        List<CityAreaDto> cityAreaDtoList4 = new ArrayList<>();

                        CityAreaDto cityAreaDto3 = new CityAreaDto();

                        cityAreaDto3.setCity(street);
                        cityAreaDto3.setRegions(citys4);
                        cityAreaDtoList4.add(cityAreaDto3);
                        if (organizationUser.getOrganizationType() == 3) {
                            Map map46 = new HashMap();
                            map46.put("street", street);
                            List<BreedFactory> breedFactoryList4 = (List<BreedFactory>) breedFactoryReadService.findByArea(map46).getResult();
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                            map.put("breedFactorys", breedFactoryList4);
                        } else {
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        }


                        map.put("cityAreaDtoList", cityAreaDtoList4);

                        //switch break;
                        break;
                    case 5://村
                        UserProfile userProfile5 = userProfileReadService.findUserProfileById(userResponse.getResult().getId()).getResult();

                        List<GovernmentUserDuty> governmentUserDutyList = governmentUserDutyReadService.findGovernmentUserDutiesByUserId(userResponse.getResult().getId(), null).getResult();
                        List<Long> longlist = new ArrayList<>();
                        for (GovernmentUserDuty governmentUserDuty : governmentUserDutyList) {
                            longlist.add(governmentUserDuty.getFactoryOrPointId());
                        }
                        List<String> villages = new ArrayList<>();
                        List<BreedFactory> breedFactoryList2 = breedFactoryReadService.findBreedFactoryDtoByIds(longlist).getResult();
                        for (BreedFactory breedFactory : breedFactoryList2) {
                            villages.add(breedFactory.getVillage());
                            ;
                        }

                        List<String> listWithoutDup = new ArrayList<String>();
                        List<CityAreaDto> cityAreaDtoList5 = new ArrayList<>();
                        CityAreaDto cityAreaDto1 = new CityAreaDto();
                        cityAreaDto1.setCity(userProfile5.getCity());
                        listWithoutDup.add(userProfile5.getRegion());

                        // cityAreaDto1.setCity(village);
                        cityAreaDto1.setRegions(listWithoutDup);

                        cityAreaDtoList5.add(cityAreaDto1);

                        map.put("userProfile", userProfile5);
                        if (organizationUser.getOrganizationType() == 3) {
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                            map.put("breedFactorys", breedFactoryList2);
                        } else {
                            map.put("OrganizationType", organizationUser.getOrganizationType());
                        }

                        map.put("cityAreaDtoList", cityAreaDtoList5);

                        //switch break;
                        //switch break;
                        break;
                }
                break;
            }
        }
        return map;
    }
}
